package com.heaven.customerServer.customerController;

import com.heaven.customerServer.customerController.vo.register.RegisterReq;
import com.heaven.customerServer.customerController.vo.register.RegisterRes;
import com.heaven.service.RegisterService;
import com.heaven.utils.R;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("heaven-server/register")
public class RegisterController {
    @Resource
    private RegisterService registerService;

    @GetMapping("/get-checkcode")
    public Mono<R> getCheckCode(@RequestParam("email") String email){
        RegisterRes ans = registerService.getCheckCodeByEmail(email);
        return Mono.just(ans.isSuccess() ? R.ok() : R.error(ans.getMessage()));
    }

    @PostMapping("/verify-checkcode")
    public Mono<R> verify(@RequestBody @Valid RegisterReq req){
        RegisterRes ans = registerService.verifyCheckCode(req);
        return Mono.just(ans.isSuccess() ? R.ok() : R.error(ans.getMessage()));
    }

}
